package com.nefu.huiyi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nefu.huiyi.entity.Doctor;
import com.nefu.huiyi.entity.Material;
import com.nefu.huiyi.mapper.IMaterialMapper;
import com.nefu.huiyi.service.MaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;



@Slf4j
@Service
public class MaterialServiceImpl implements MaterialService {

    @Autowired
    private IMaterialMapper materialMapper;


    @Override
    public Material addMaterial(Material material) {
        materialMapper.insert(material);
        return material;
    }

    @Override
    public boolean deleteMaterial(Integer id) {
        return materialMapper.deleteById(id) > 0;
    }

    @Override
    public Material getMaterialById(Integer id){
        return (Material) materialMapper.selectById(id);
    }

    @Override
    public Material updateMaterial(Material material) {
        materialMapper.updateById(material);
        return (Material) materialMapper.selectById(material.getId());
    }

/*    @Override
    public List<Material> searchByKeyword(String keyword) {
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        if (keyword != null && !keyword.isEmpty()) {
            wrapper.like(Material::getName, keyword)
                    .or().like(Material::getCategory, keyword);
        }
        return materialMapper.selectList(wrapper);
    }*/


    @Override
    public IPage<Material> getMaterialPage(Page<Material> page, String keyword) {
        LambdaQueryWrapper<Material> wrapper = new LambdaQueryWrapper<>();
        if (keyword != null && !keyword.trim().isEmpty()) {
            wrapper.like(Material::getName, keyword)
                    .or().like(Material::getCategory, keyword);// 模糊查
        }
        return materialMapper.selectPage(page, wrapper);
    }

}
